// Vant
import { Toast, Dialog } from "vant";
import "vant/es/toast/style";
import "vant/es/dialog/style";
import myAxios from "../utils/http";

export default () => {
  const _axios = async ({
    api = "",
    method = "post",
    params = {},
    loading = false,
  }) => {
    let load;
    if (loading) {
      load = Toast.loading({
        duration: 0,
        forbidClick: true,
        message: "请等待",
      });
    }
    const res = await myAxios[method](
      api,
      method === "post" ? params : { params }
    );

    if (load) {
      load.clear();
    }

    return res;
  };

  return {
    _axios,
  };
};
